﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;

namespace CRM
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {

        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            for (int i = 0; i < Request.QueryString.Count; i++)
            {
                if (Common.CheckMes.CheckKeyWord(Request.QueryString[i].ToString()))
                {
                    Model.T_SysLogInfo ModelLog = new CRM.Model.T_SysLogInfo();
                    ModelLog.T_LogIP = Common.GetMes.GetIp();
                    ModelLog.T_LogNote = "【" + Request.Url.AbsolutePath + "】非法的Url参数";
                    ModelLog.T_Remark = "<font color=red>[系统错误日志]</font>";
                    try
                    {
                        BLL.SysLogInfo.EditLogInfo(ModelLog);
                    }
                    catch (Exception ex)
                    {
                        Common.FileComm.WriteFile(Server.MapPath("~/ErrorLog/log.log"), "\n\t【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "】\n\t【错误1】【" + Request.Url.AbsolutePath + "】非法的Url参数" + "\n\t【错误2】" + ex.Message);
                    }
                    finally
                    {
                        Response.Redirect("~/Error.html");
                    }
                }
            }
        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {
            //Exception objErr = Server.GetLastError().GetBaseException();
            //Server.ClearError();
            //try
            //{
            //    Model.T_SysLogInfo ModelLog = new CRM.Model.T_SysLogInfo();
            //    ModelLog.T_LogIP = Common.GetMes.GetIp();
            //    ModelLog.T_LogNote = "【" + Request.Url.AbsolutePath + "】" + Server.HtmlEncode(objErr.Message);
            //    ModelLog.T_Remark = "<font color=red>[系统错误日志]</font>";
            //    BLL.SysLogInfo.EditLogInfo(ModelLog);
            //}
            //catch (Exception ex)
            //{
            //    Common.FileComm.WriteFile(Server.MapPath("~/ErrorLog/log.log"), "\n\t【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "】\n\t【错误1】" + objErr.Message + "\n\t【错误2】" + ex.Message);
            //}
            //finally
            //{
            //    Response.Redirect("~/Error.html");
            //}
        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}